using Microsoft.EntityFrameworkCore;
using Quant.Entities;

namespace Quant.Data
{
    public class AppDbContext : DbContext
    {
        public DbSet<SystemSetting> SystemSettings { get; set; }
        public DbSet<StrategyConfig> StrategyConfigs { get; set; }
        public DbSet<TradeRecord> TradeRecords { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlServer("Server=.;Database=QuantTrading;Trusted_Connection=True;");
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<SystemSetting>().Property(s => s.ParamValue).HasPrecision(18, 8);
            modelBuilder.Entity<StrategyConfig>().Property(s => s.FixedAmount).HasPrecision(18, 8);
            modelBuilder.Entity<StrategyConfig>().Property(s => s.PositionRatio).HasPrecision(5, 4);
            modelBuilder.Entity<TradeRecord>().Property(t => t.Quantity).HasPrecision(18, 8);
            modelBuilder.Entity<TradeRecord>().Property(t => t.ExecutedPrice).HasPrecision(18, 8);
            modelBuilder.Entity<TradeRecord>().Property(t => t.PositionValue).HasPrecision(18, 8);
        }
    }
}